#!/usr/bin/env python3

# 例子：发布一个话题信息
import rospy
from std_msgs.msg import String

def talker():
    pub = rospy.Publisher("chatter",String,queue_size=10)   # 创建发布者
    rospy.init_node("talker",anonymous=True)                # 初始化节点
    rate = rospy.Rate(10)                                   # 设置发布频率
    while not rospy.is_shutdown():
        hello_str = "hello world %s" % rospy.get_time()     
        rospy.loginfo(hello_str)
        pub.publish(hello_str)  # 发布信息
        rate.sleep()    # 按频率睡眠

if __name__ == "__main__":
    try:
        talker()
    except rospy.exceptions:
        pass
